<template>
    <div id='user'>
        <P></P>
        <el-table :data="tableData" border style="width: 100%">
            <el-table-column prop="id" label="ID" width="100">
            </el-table-column>
            <el-table-column prop="username" label="用户名" width="180">
            </el-table-column>
            <el-table-column prop="email" label="邮箱">
            </el-table-column>
            <el-table-column prop="phone" label="电话">
            </el-table-column>
            <!-- <el-table-column label="注册时间" prop="createTime" :formatter="formatTime"></el-table-column> -->
            <el-table-column label="注册时间">
                <template v-slot="scope">
                    {{scope.row.createTime|times}}
                </template>
            </el-table-column>
        </el-table>
        <Paginations :obj="obj" @pagenum="handleCurrentChange" @pagesize="handleSizeChange"></Paginations>
    </div>
</template>

<script>
    import {
        Table,
        TableColumn,
    } from 'element-ui'
    import P from './P.vue';
    import Time from '../../utils/Time'
    import {
        userList
    } from '../../api';
    import Paginations from './Paginations.vue';
    export default {
        components: {
            Paginations,
            P,
            'el-table': Table,
            'el-table-column': TableColumn,
        },
        data() {
            return {
                obj: {
                    total: 0,
                    pageNum: 1,
                    pageSize: 10
                },
                tableData: []
            };
        },
        methods: {
            async getUser(Num) {
                let {
                    data: res
                } = await userList(Num)
                this.tableData = res.data.list
                this.obj.total = res.data.total
                console.log(res);
            },

            handleSizeChange(val) {
                // console.log(`每页 ${val} 条`);
                this.obj.pageSize = val
                this.getUser(this.obj)
            },
            handleCurrentChange(val) {
                // console.log(`当前页: ${val}`);
                this.obj.pageNum = val
                console.log(this.obj);
                this.getUser(this.obj)
            },
            formatTime(row, column, cellValue, index) {
                console.log(row.createTime);
                return Time(row.createTime)
            },
        },
        mounted() {
            this.getUser(this.obj)
        },
        computed: {

        }
    }
</script>
<style lang='scss' scoped>

</style>